<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<title>用户信息添加</title>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <%@include file="/WEB-INF/common/hplus-js.jsp" %>
    <style type="text/css">
    #required{
	color:red;
}
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <form action="${path}/user/add" class="form-horizontal m-t" id="userForm" method="post" enctype="multipart/form-data">
                            <input type="hidden" name='orgId' value='${user.orgId}'/>
                            <input  name="pid" id="pid" type="hidden" value="">
                            <div class="form-group">
                               		 <label class="col-sm-3 control-label">用户类型：</label>
                            		 <div class="col-sm-8">
                            			<select name="type"  class="col-sm-6" id="org" style=" height:26px; line-height:26px; text-align: center;">
		                            		<c:if test="${user.type=='1' }">
		                            			<option value="1">超级管理员</option>
		                            			<option value="5">系统运营(回收员........)</option>
                                            </c:if>
                                            <c:if test="${user.type=='3' }">
                                            <option value="3">机构用户</option>
                                            </c:if>
		                            	</select>
                            		</div>
                          		 </div>

                            <c:if test="${user.type!=3}">
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span>*</span>登录账号：</label>
                                <div class="col-sm-4">
                                    <input type="text"  name="name"  class="form-control" aria-required="true"  required="required"  maxlength="11" placeholder="请输入登录用户名"
                                    onkeyup="value=value.replace(/[\u4e00-\u9fa5]/ig,'')">
                                </div>
                            </div>
                             <div class="form-group">
                                <label class="col-sm-3 control-label"><span >*</span>登录密码：</label>
                                <div class="col-sm-4">
                                    <input type="password" class="form-control" aria-required="true"  required="required" name="password" placeholder="请输登录入密码">
                                </div>
                            </div>
                            </c:if>


                         <div id="pu">
                             <div class="form-group" id="trueN">
                                <label class="col-sm-3 control-label">真实性名：</label>
                                <div class="col-sm-4">
                                    <input type="text" id="trueName"  maxlength="24" name="trueName" aria-required="true"  required="required" minlength="2" class="form-control"  value="" placeholder="请输入真实姓名" >
                                </div>
                            </div>
                            <div class="form-group" id="phone">
                                <label class="col-sm-3 control-label">手机号：</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" aria-required="true"  required="required" name="mobile" id="mobile" isPhone="true"  placeholder="请输入手机号 ">
                                </div>
                            </div>

                            <div class="form-group" id="sex">
                                <label class="col-sm-3 control-label"><span id="required" >*</span>用户性别：</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b" name="gender" >
                                        <option value="1" >男</option>
                                        <option value="0" >女</option>
                                    </select>
								</div>
                            </div>
                      </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">用户角色：</label>
                                <div class="col-sm-8" id="roles">
                                    <c:forEach items="${roles}" var="role" varStatus="i">

                                            <label class="radio-inline i-checks">
                                                <div class="iradio_square-green
                                                   <c:forEach var="ur" items="${user.roles}" varStatus="i">
                                                        <c:if test="${ur.id == role.id}"> checked='checked'</c:if>
                                                    </c:forEach>" style="position: relative;">

                                                    <input name="roleId" type="radio" style="position: absolute; opacity: 0;" value="${role.id}"
                                                    <c:forEach var="ur" items="${user.roles}" varStatus="i">
                                                    <c:if test="${ur.id != role.id}"> checked </c:if>
                                                    </c:forEach> >
                                                    <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
                                                </div>
                                                    ${role.nameZh}
                                            </label>
                                    </c:forEach>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3">
                                    <button class="btn btn-primary" id="add-btn" type="button">添加用户</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@include file="/WEB-INF/common/hplus-suggest-js.jsp"%>
    <!--手机号 生分证，表单校验插件 -->
<script src="${pageContext.request.contextPath}/assets/js/validate/dist/additional-methods.js"></script>

    <script src="${path}/assets/hplus/js/demo/form-validate-demo.js"></script>
    <script>
  //模糊下拉单位自动填充信息
    function ffindUnitList(inputId){
  	$("#" + inputId).bsSuggest({
  		clearable: true,
  		url : "${path}/organ/query",
  		idField : "id",
  		keyField : "name",
  		effectiveFields : [ "name" ],
  		emptyTip: '查询结果给为空...',
  		listStyle: {
  	        'padding-top': 0,
  	        'height': '175px',
  	        'max-width': '800px',
  	        'overflow': 'auto',
  	        'transition': '0.3s',
  	        '-webkit-transition': '0.3s',
  	        '-moz-transition': '0.3s',
  	        '-o-transition': '0.3s'
  	    }, 
  	}).on("onSetSelectValue", function(e, keyword) { //选择时
  		$("#pid").val(keyword.id);
  	});
  }


    //模糊下拉公安自动填充信息
    function ffindPoiceList(inputId){
  	$("#" + inputId).bsSuggest({
  		clearable: true,
  		url : "${path}/police/suggest?keywords=",
  		idField : "id", //id字段
  		keyField : "name",
  		effectiveFields : [ "name" ],
  		emptyTip: '查询结果给为空...',
  		listStyle: {
  	        'padding-top': 0,
  	        'height': '175px',
  	        'max-width': '800px',
  	        'overflow': 'auto',
  	        'transition': '0.3s',
  	        '-webkit-transition': '0.3s',
  	        '-moz-transition': '0.3s',
  	        '-o-transition': '0.3s'
  	    },
  	}).on("onSetSelectValue", function(e, keyword) { //选择时
  		$("input[name='policeId']").val(keyword.id);
  		$("input[name='unitOrPolice']").val($("input[name='policeName']").val());
  	});
  }
        $(document).ready(function () {
        	// 在键盘按下并释放及提交后验证提交表单
            $("#userForm").validate({
                  rules: {
                	  password: "required",
                	  name: "required",

                  },
                  messages: {
                	  password: "必填",
                	  name: "必填",

                  }, invalidHandler: function(form, validator) {
                      var errors = validator.numberOfInvalids();
                      if (errors) {
                          validator.errorList[0].element.focus();
                      }
                  }
              })
             //获取用户的type:1企业\2公安 \3超级管理员
           		var hiType=$("#hiddenType").val();
              if (hiType=="3") {
	        	//对所属下拉的控制显示
	        	var types=$("select[name='type']").val();
	        	if (types=='1') {
	        			document.getElementById("companyId").style.display="inline";
	        			document.getElementById("policeId").style.display="none";
	        			document.getElementById("pc").style.display="none";//隐藏用户所属

					//默认所属信息的默认值
	            	window.onload=function(){
	            		  var osel=document.getElementById("companyId"); //得到select的ID
	            		  var opts=osel.getElementsByTagName("option");//得到数组option
	            		  opts[1].selected=true;//设置option第4个元素,即value="3"为默认选中
	        		}
				}else if(types=='2'){
					document.getElementById("pc").style.display="none";//隐藏用户所属
					document.getElementById("policeId").style.display="inline";
					document.getElementById("companyId").style.display="none";
					//默认所属信息的默认值
		        	window.onload=function(){
		      		  var osel=document.getElementById("policeId"); //得到select的ID
		      		  var opts=osel.getElementsByTagName("option");//得到数组option
		      		  opts[1].selected=true;//设置option第4个元素,即value="3"为默认选中
		        	}
				}else if(types=='3'){
					document.getElementById("policeId").style.display="none";
					document.getElementById("companyId").style.display="none";
				}else if(types=='4'){
					document.getElementById("policeId").style.display="none";
					document.getElementById("companyId").style.display="none";
				}
              }
        	$(".company").on("change",function(){
        		var option = $(this).find("option:selected");
        		$(".unitOrPolice").val(option.attr("policeName"))
        	})

        	$("select[name='type']").change(function(){
        		var ty=$(this).val();
        		if (hiType=="3") {
        		if (ty=='1') {
        			document.getElementById("yonghusuoshu").style.display="inline";
        			document.getElementById("pu").style.display="inline";
            		document.getElementById("companyId").style.display="inline";
            		document.getElementById("policeId").style.display="none";
            		document.getElementById("phone").style.display="inline";
            		document.getElementById("card").style.display="inline";
            		document.getElementById("sex").style.display="inline";
            		document.getElementById("warningSig").style.display="none";//影藏警号
            		document.getElementById("faceRe").style.display="inline";//显示人脸识别
            		document.getElementById("posi").style.display="inline";//显示职位
            		document.getElementById("unitOrPolices").style.display="none";//隐藏单位
    				//默认所属信息的默认值
                	window.onload=function(){
                		  var osel=document.getElementById("companyId"); //得到select的ID
                		  var opts=osel.getElementsByTagName("option");//得到数组option
                		  opts[1].selected=true;//设置option第4个元素,即value="3"为默认选中
                	}
    			}else if(ty=='2'){
    				document.getElementById("pu").style.display="inline";
    				document.getElementById("policeId").style.display="inline";
    				document.getElementById("companyId").style.display="none";
    				document.getElementById("phone").style.display="inline";
    				document.getElementById("yonghusuoshu").style.display="inline";
            		document.getElementById("card").style.display="inline";
            		document.getElementById("sex").style.display="inline";
            		document.getElementById("warningSig").style.display="inline";//显示警号
            		document.getElementById("faceRe").style.display="inline";//显示人脸识别
            		document.getElementById("posi").style.display="inline";//显示职位
            		document.getElementById("unitOrPolices").style.display="inline";//显示单位

    				//默认所属信息的默认值
    	        	window.onload=function(){
    	      		  var osel=document.getElementById("policeId"); //得到select的ID
    	      		  var opts=osel.getElementsByTagName("option");//得到数组option
    	      		  opts[1].selected=true;//设置option第4个元素,即value="3"为默认选中
    	        	}
    			}else if(ty=='4'){
    				document.getElementById("pu").style.display="inline";
    				document.getElementById("policeId").style.display="none";
    				document.getElementById("companyId").style.display="none";
    				document.getElementById("yonghusuoshu").style.display="none";
    				document.getElementById("phone").style.display="inline";
            		document.getElementById("card").style.display="inline";
            		document.getElementById("sex").style.display="inline";
            		document.getElementById("warningSig").style.display="none";
            		document.getElementById("faceRe").style.display="inline";//显示人脸识别
            		document.getElementById("posi").style.display="none";//显示职位
    			}else{
    				document.getElementById("yonghusuoshu").style.display="none";
    				document.getElementById("pu").style.display="none";
    				document.getElementById("policeId").style.display="none";
    				document.getElementById("companyId").style.display="none";
    				document.getElementById("phone").style.display="none";
            		document.getElementById("card").style.display="none";
            		document.getElementById("sex").style.display="none";
            		document.getElementById("warningSig").style.display="none";
            		document.getElementById("faceRe").style.display="none";//显示人脸识别
            		document.getElementById("posi").style.display="none";//显示职位
            		document.getElementById("unitOrPolices").style.display="none";//显示单位
    			}
        		}
        	})
        	/* $("#userForm").validate(); */
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
            
            $("#add-btn").click(function() {
            	var valid = $("#userForm").valid();
            	if(valid) {

            		var roleIds = $("input[name='roleId']:checked").val();
            		if(roleIds=='' || roleIds==undefined) {
            			layer.msg('请选择用户角色',{icon: 5,time:1000});
            			return false;
            		}
            		$("#userForm").ajaxSubmit({
                        dataType: "json",
                        success: function (json) {
                            var code = json.code;
                            if(code == 0){
                            	layer.msg('添加成功', {icon: 1});
                                setTimeout(function(){
                                	window.parent.location.reload();
                                	parent.parent.layer.closeAll();
                                }, 1000);
                            }else{
                            	layer.msg(json.msg, {icon: 5,time:2000});
                            }
                        },
                        error:function(){
                        	layer.msg('添加发生错误', {icon: 5});
                        }
                    });
            	}else{
            		layer.msg("请填写完整信息！！！！", {
						icon : 5
					});
            	}
            });
        });

  var index =null;
  function choose() {
      index =  layer.open({
          type: 2,
          title: '',
          shadeClose: true,
          shade: 0.5,
          area: ['500px', '100%'],
          content: '${path}/organ/tree' //iframe的url
      });
  }

  function closeTree(id,name) {
      console.log("id="+id);
      $("#pid").val(id);
      $("#name").val(name);
      layer.close(index);
  }
    </script>

</body>
</html>
